package com.zty.user.designPattern.templatePattern.prod;


import com.zty.bean.Result;
import com.zty.bean.ResultCode;


/**
 * @Author ZTY
 * @Description 模板模式实际应用api（定义模板行为）
 * @Date 1:53 2023-12-15
 **/

public class ApiTemplate {

    /**
     * 模板行为
     *
     * @param result
     * @param action
     */
    public void execute(Result result, final Action action) {
        try {
            action.validate();
            action.execute();
            action.after();
            result.setSuccess(true);
            result.setCode(ResultCode.SUCCESS);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setCode(ResultCode.ERROR);
        }
    }
}
